﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>发起限制规则</title>
    <!--SQL编辑器-->
    <link href="../../Scripts/CodeMirror/lib/codemirror.css" rel="stylesheet" />
    <link href="../../Scripts/CodeMirror/addon/hint/show-hint.css" rel="stylesheet" />
    <script src="../../Scripts/CodeMirror/lib/codemirror.js"></script>
    <script src="../../Scripts/CodeMirror/addon/edit/matchbrackets.js"></script>
    <script src="../../Scripts/CodeMirror/mode/sql/sql.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/show-hint.js"></script>
    <script src="../../Scripts/CodeMirror/addon/hint/sql-hint.js"></script>
    <script src="../../LoadSql.js"></script>
    
    <link href="../../Scripts/easyUI145/themes/color.css" rel="stylesheet" />
    <link href="../../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .input {
            width: 95%;
            height: 20px;
        }
    </style>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../Scripts/QueryString.js"></script>
    <!-- ccbpm -->
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <base target="_self" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI145/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/easyUI145/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../../Scripts/easyUI145/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/easyUI145/locale/easyui-lang-zh_CN.js"></script>
    <script src="../Admin.js"></script>

    <script type="text/javascript">


        //全局变量
        var FK_Flow; 	//流程id
        var _StartLimitRole; //限制规则枚举（JSON)

        //页面启动函数.
        $(function () {



            $("#Msg").html("<img src=../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");

        });

        function InitPage() {

            var fk_flow = GetQueryString("FK_Flow");

            var data = new Entity("BP.WF.Flow", fk_flow);

            var _StartLimitRole = data.StartLimitRole;

            //批量赋值.
            GenerFullAllCtrlsVal(data);

            if (_StartLimitRole == 1) {
                $("#RB_ByTime").attr("checked", true);
                $("#TB_ByTimePara").val(data.StartLimitPara);
                $("#DDL_ByTime").val(0);
            }

            var dat = data;
            $("#TB_Alert").val(dat.StartLimitAlert); //限制提示信息
            switch (parseInt(dat.StartLimitRole)) {
                case 0: //不限制 None
                    $("#RB_None").attr("checked", true);
                    //$("input[name=xzgz][value=RB_None]").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara); //for test
                    break;
                case 1: //天
                    $("#RB_ByTime").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara);
                    $("#DDL_ByTime").val(0);
                    break;
                case 2: //周
                    $("#RB_ByTime").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara);
                    $("#DDL_ByTime").val(1);
                    break;
                case 3: //月份
                    $("#RB_ByTime").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara);
                    $("#DDL_ByTime").val(2);
                    break;
                case 4: 	//月份？
                    $("#RB_ByTime").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara);
                    $("#DDL_ByTime").val(3);
                    break;
                case 5: //年度
                    $("#RB_ByTime").attr("checked", true);
                    $("#TB_ByTimePara").val(dat.StartLimitPara);
                    $("#DDL_ByTime").val(4);
                    break;
                case 6: 		//发起的列不能重复,(多个列可以用逗号分开)
                    $("#RB_ColNotExit").attr("checked", true);
                    $("#TB_ColNotExit_Fields").val(dat.StartLimitPara);
                    break;
                case 7: 	//<=0
                    $("#RB_SQL").attr("checked", true);
                    $("#TB_SQL").val(dat.StartLimitPara);
                    $("#DDL_SQL").val(0);
                    break;
                case 8: //>0
                    $("#RB_SQL").attr("checked", true);
                    $("#TB_SQL").val(dat.StartLimitPara);
                    $("#DDL_SQL").val(1);
                    break;
                case 9: 	//为子流程时仅仅只能被调用1此
                    $("#RB_OnlyOneSubFlow").attr("checked", true);
                    break;
                default:
                    alert('没有判断的类型.');
                    break;
            }
            $("#Msg").html("");

        }

        function Save(parameters) {
            //debugger;
            //获取控件值
            var startLimitRole = "", startLimitPara = "";
            var xzgz = $("input[name=xzgz]:checked")[0].id; //$("input[type=radio][name=xzgz]:checked")[0].id
            switch (xzgz) {
                case "RB_None":
                    startLimitRole = "0";
                    break;
                case "RB_ByTime":
                    var DDL_ByTime = parseInt($("#DDL_ByTime").val());
                    switch (DDL_ByTime) {
                        case 0:
                            startLimitRole = "1";
                            break;
                        case 1:
                            startLimitRole = "2";
                            break;
                        case 2:
                            startLimitRole = "3";
                            break;
                        case 3:
                            startLimitRole = "4";
                            break;
                        case 4:
                            startLimitRole = "5";
                            break;
                    }
                    startLimitPara = $("#TB_ByTimePara").val();
                    break;
                case "RB_OnlyOneSubFlow":
                    startLimitRole = "9";
                    break;
                case "RB_ColNotExit":
                    startLimitRole = "6";
                    startLimitPara = $("#TB_ColNotExit_Fields").val();
                    break;
                case "RB_SQL":
                    var DDL_SQL = $("#DDL_SQL").val();
                    startLimitRole = DDL_SQL == 0 ? "7" : "8";
                    startLimitPara = $("#TB_SQL").val();
                    break;
                default:
                    break;
            }

            //            //第2代技术.
            //		    var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_AttrFlow");
            //		    handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));
            //		    handler.AddPara("StartLimitRole", startLimitRole);
            //		    handler.AddPara("StartLimitPara", startLimitPara);
            //		    handler.AddPara("StartLimitAlert", $("#TB_Alert").val());
            //		    var data = handler.DoMethodReturnString("Limit_Save");

            //		    if (data.indexOf("err@") == 0) {
            //		        alert(data);
            //		        return;
            //		    }
            //		    alert(data);

            //第3代技术.
            var flow = new Entity("BP.WF.Flow", GetQueryString("FK_Flow"));
            flow.StartLimitRole = startLimitRole;
            flow.StartLimitPara = startLimitPara;
            flow.StartLimitAlert = $("#TB_Alert").val();
            flow.Update();


            window.location.href = window.location.href;

        }

        function Help() {
            var url = "http://ccbpm.mydoc.io";
            window.open(url);
        }
    </script>
    <style type="text/css">
        /*body.easyui-layout {
            top: 20px;
            left: 40px;
        }*/
        .panel-body {
            padding: 0px;
        }

        .tabs {
            border-width: 1px 0 1px 0;
        }

        .btn-default {
            border: 0px;
        }

        .cs-btn-group {
            width: auto !important;
            min-height: 34px;
            text-align: right;
            background-color: transparent;
        }

            .cs-btn-group .l-btn-icon {
                display: none;
            }

            .cs-btn-group .l-btn-text {
                margin: 0;
            }

        .layout-panel {
            position: absolute;
            right: 0;
            top: 0 !important;
            box-shadow: none;
        }

        .layout-panel-north {
            width: auto !important;
            left: auto !important;
            background-color: transparent;
        }

        .btn {
            padding: 0 10px;
            color: #fff !important;
            border-radius: 0px !important;
            border: 0;
            height: 24px;
            line-height: 24px;
            box-sizing: border-box;
        }

            .btn:hover {
                padding: 0 10px;
                border: 0;
            }

        .btn-light-green {
            background-color: #50b6ac !important;
        }

            .btn-light-green:hover {
                background-color: #50b6ac;
            }

        .btn-light-blue {
            background-color: #62cae3 !important;
        }

            .btn-light-blue:hover {
                background-color: #62cae3;
            }

        .btn-light-yellow {
            background-color: #f3ba20 !important;
        }

            .btn-light-yellow:hover {
                background-color: #f3ba20;
            }

        .btn-light-red {
            background-color: #f74f52 !important;
        }

            .btn-light-red:hover {
                background-color: #f74f52;
            }

        .btn-white {
            border: 1px solid #031f5d;
            background-color: #fff !important;
            ;
            color: #031f5d !important;
        }

            .btn-white:hover {
                border: 1px solid #031f5d;
            }

        .tabs-wrap .tabs, .tabs-panels, .tabs li a.tabs-inner, .tabs-panels table, td.FDesc, td.FContext, td {
            border: 0;
        }

        .tabs-wrap table {
            width: 100% !important;
        }

        .tabs-wrap .tabs {
            padding-left: 0;
            width: auto;
            border-bottom: 1px solid #0a2561;
        }

        .tabs li a.tabs-inner {
            padding: 0 16px;
            background: none;
            border-radius: 5px 5px 0 0;
        }

            .tabs li a.tabs-inner:hover {
                background: none;
                font-weight: bold;
            }

        .tabs li.tabs-selected a.tabs-inner {
            border: 1px solid #0a2561;
            border-bottom-color: #fff;
            background: #fff;
        }

        td {
            box-sizing: border-box;
        }

            td a {
                color: #15398b;
                font-size: 12px;
            }

                td a img {
                    vertical-align: -2px;
                }

            td.FContext {
                width: 30%;
            }

                td.FContext:nth-child(2) {
                    padding-right: 30px;
                }

                td.FContext > *:only-child {
                    width: 100% !important;
                    font-size: 13px;
                    color: #282828;
                    box-sizing: border-box;
                }

                td.FContext[colspan] {
                    padding-right: 0;
                }

        select[disabled], input[type=text]:disabled, .form-control, .form-control[disabled], .form-control[readonly], fieldset[disabled] {
            background-color: #fff;
            border: 1px solid #ccc !important;
            text-align: left !important;
            height: 32px;
            box-sizing: border-box;
        }

            select[disabled], input[type=text]:disabled, .form-control[disabled], .form-control[readonly], fieldset[disabled] {
                background-color: #f7f6f9;
            }

        td input[type="text"], td input[type="number"], td input[type="date"], td input[type="tel"] {
            height: 32px;
        }

        td input[type="checkbox"] {
            margin-right: 5px;
            width: 16px;
            height: 16px;
        }

        td label {
            font-size: 13px;
        }

        /*td.FDesc {
           padding-right: 10px;
            text-align: right;
            box-sizing: border-box;
        }*/
        /*td.FDesc:first-child {
            width: 81px!important;
        }
        td:nth-child(3)[class="FDesc"] {
            width: 130px!important;
        }*/
        .cs-form-import > .layout-panel-center {
            padding: 16px 0 0 16px;
        }

        .cs-form-import > .layout-panel-north {
            top: 6px !important;
            padding-right: 21px;
            border-radius: 0;
        }
    </style>
</head>
<body>
    <div id="bar" class="cs-tr cs-bar">
        <label style="float:left;font-size:13px;font-weight:bolder;padding-top:10px;">发起限时规则</label>
        <input type="button" id="Btn_Save" runat="server" value="保存" onclick="Save()" />
    </div>

    <fieldset>
        <legend>
            <input type="radio" name="xzgz" id="RB_None" value="RB_None">
            <!-- checked="checked"> -->
            <label style="font-size:13px;font-weight:bolder;" for="RB_None">
                不限制（默认）
            </label>
        </legend>
        <ul style="color: Gray">
            <li>不限制发起次数，比如报销流程、请款流程。</li>
            <br />
        </ul>
    </fieldset>
    <fieldset>
        <legend>
            <br />
            <input type="radio" name="xzgz" id="RB_ByTime">
            <label style="font-size:13px;font-weight:bolder;" for="RB_ByTime">
                按时间规则计算
            </label>
            <br />
            <br />
        </legend>
        <table style="width: 100%">
            <tr>
                <td style="width: 80px;">
                    规则模式：
                </td>
                <td>
                    <br />
                    <select id="DDL_ByTime">
                        <option value="0">每人每天一次</option>
                        <option value="1">每人每周一次</option>
                        <option value="2">每人每月一次</option>
                        <option value="3">每人每季一次</option>
                        <option value="4">每人每年一次</option>
                    </select>
                    <br />
                </td>

            </tr>
            <tr>
                <td colspan="3">
                    <a href="javascript:ShowHidden('FQGZ')">发起时间段限制参数设置:</a>
                    <br>
                    <div id="FQGZ" style="display: none; color: Gray">
                        <ul>
                            <li>该设置，可以为空。</li>
                            <li>用来限制该流程可以在什么时间段内发起。</li>
                            <li>例如:按照每人每天一次设置时间范围，规则参数：@08:30-09:00@18:00-18:30，解释：该流程只能在08:30-09:00与18:00-18:30两个时间段发起且只能发起一次。</li>
                        </ul>

                    </div>
                    <input type="text" class="input" id="TB_ByTimePara">
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset>
        <legend>
            <input type="radio" name="xzgz" id="RB_OnlyOneSubFlow">
            <label style="font-size:13px;font-weight:bolder;" for="RB_OnlyOneSubFlow">
                为子流程时的规则.
            </label>
        </legend>
        <ul>
            <li><label> <input type="checkbox" id="" /> 如果当前为子流程，仅仅只能被调用1次，不能被重复调用。</label></li>
            <li><label> <input type="checkbox" /> 如果当前为子流程，需要等到指定的子流程结束以后才能启动该流程。</label></li>

            <li>指定的流程编号:<input type=text />多个子流程用逗号分开.比如:001,003</li>
            <br />
        </ul>
    </fieldset>

    <fieldset>
        <legend>
            <input type="radio" name="xzgz" id="RB_ColNotExit">
            <label style="font-size:13px;font-weight:bolder;" for="RB_ColNotExit">
                按照发起字段不能重复规则
            </label>
            <br />
            <br />
        </legend><a href="javascript:ShowHidden('fields')">填写设置字段</a>
        <div id="fields" style="display: none; color: Gray">
            <ul>
                <li>设置一个列允许重复，比如：NSRBH</li>
                <li>设置多个列的时候，需要用逗号分开，比如：field1,field2</li>
                <li>流程在发起的时候如果发现，该列是重复的，就抛出异常，阻止流程发起。</li>
                <li>比如：纳税人注销流程，一个纳税人只能发起一次注销，就要配置纳税人字段，让其不能重复。</li>
            </ul>
        </div>
        <input type="text" class="input" id="TB_ColNotExit_Fields">
    </fieldset>
    <fieldset>
        <legend>
            <br />
            <input type="radio" name="xzgz" id="RB_SQL">
            <label style="font-size:13px;font-weight:bolder;" for="RB_SQL">
                按SQL规则
            </label>
            <br />
            <br />
        </legend>
        <!-- &nbsp;&nbsp; -->
        <span>规则模式：</span>
        <br>
        <select name="规则模式" id="DDL_SQL">
            <option value="0">设置的SQL数据为空，或者返回结果为零时可以启动</option>
            <option value="1">设置的SQL数据为空，或者返回结果为零时不可以启动</option>
        </select>
        <br>
        <a href="javascript:ShowHidden('Div2')">SQL规则参数:</a>
        <br>
        <div id="Div2" style="display: none; color: Gray">
            <ul>
                <li>例如：SELECT COUNT(*) AS Num FROM TABLE1 WHERE NAME='@MyFieldName'</li>
                <li>解释：编写一个sql语句返回一行一列，如果信息是0，就是可以启动，非0就不可以启动。</li>
                <li>该参数支持ccbpm的表达式。比如:@WebUser.No,@WebUser.Name,@WebUser.FK_Dept,@WebUser.OrgNo</li>
            </ul>
        </div>
        <textarea class="input" id="TB_SQL" name="TB_SQL" rows="3" style="height: 45px;"></textarea>
    </fieldset>
    <fieldset>
        <legend><a href="javascript:ShowHidden('msgAlert')">限制提示信息:</a></legend>
        <div id="msgAlert" style="display: none; color: Gray">
            <ul>
                <li>例如:您的发起的流程违反了xxx限制规则，不能发起该流程。</li>
                <li>当限制规则起作用的时候，应该提示给用户什么信息。</li>
                <li>该信息在创建工作失败的时候提示。</li>
            </ul>
        </div>
        <br>
        <input type="text" class="input" id="TB_Alert">
    </fieldset>

    <!--<tr>
        <td colspan="2" style="text-align: center;">
            <input type="button" id="Btn_Save" value="保存" onclick="Save()" />
            <input type="button" id="Button1" value="我需要帮助" onclick="Help()" />
        </td>
    </tr>-->

    <div id="Msg">
    </div>
</body>
</html>
